__author__ = 'Tins'
import logging,os,datetime
LOG_ROOT = '/data/htmlpt'
PLAY_TIME_LOG = 'play_time'
import time


def LogPayTime(_sessionid,_userid,_gameid,_other):
    getBetaLogger(PLAY_TIME_LOG).info("%s|%s|%s|%s|%s"%(_sessionid,_userid,_gameid,int(time.time()),_other))


def getBetaLogger(_path="/data/sgdata/osslog",isServer= False):
    t_dir = LOG_ROOT + "/"+ _path
    if os.path.exists(t_dir):
        pass
    else:
        os.makedirs(t_dir)
    today = str(datetime.date.today())

    _logger = logging.getLogger("%s_%s"%(t_dir,today))
    if not _logger.handlers:
        handler = logging.FileHandler(os.path.join(t_dir,"%s_log.txt"%today),"w+")
        if isServer:
            formatter = logging.Formatter('[SERVER_ERROR %(levelname)s %(asctime)s %(created)f] %(message)s')
        else:
            formatter = logging.Formatter('[OSSALL %(levelname)s %(asctime)s] %(message)s')
        handler.setFormatter(formatter)
        _logger.addHandler(handler)
        _logger.setLevel(logging.INFO)
    return _logger